package com.humngyang.com.hmy.controller;


import com.humngyang.com.hmy.entity.Role;
import com.humngyang.com.hmy.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@CrossOrigin
@RequestMapping("/RoleController")
@RestController
public class RoleController {


    @Autowired
    RoleService roleService;

    /**
     * Author : hmy
     *
     * @date 2020/2/24 20:55
     * describution : 查询所有的角色
     **/

    @RequestMapping("/getAllRole")
    public Map<String, Object> getAllRole() {
        Map<String, Object> re = new HashMap<>();
        List<Role> allRole = roleService.getAllRole();
        re.put("flag", 1);
        re.put("list", allRole);
        return re;
    }


    @RequestMapping("/addrole")
    public Map<String, Object> addrole(@RequestBody Role role) {
        Map<String, Object> addrole = roleService.addrole(role);
        return addrole;
    }


    /**
     * Author : hmy
     *
     * @date 2020/2/28 9:18
     * describution :根据id查找对应的角色
     **/
    @RequestMapping("/getRoleById")
    public Map<String, Object> getRoleById(@RequestBody Role role) {
        Map<String, Object> roleById = roleService.getRoleById(role.getRoleid());
        roleById.put("flag", 1);
        return roleById;
    }

    /**
     * Author : hmy
     *
     * @date 2020/2/28 13:09
     * describution :根据id删除角色信息，同时删除权限信息
     **/

    @RequestMapping("/deleteByRoleid")
    public Map<String, Object> deleteByRoleid(@RequestBody Role role) {
        Map<String, Object> re = new HashMap<>();
        roleService.deleteByRoleid(role.getRoleid());
        re.put("flag", 1);
        return re;
    }


}
